package com.api.shopapi.mapper;

import com.api.shopapi.entity.GoodsPrice;
import com.api.shopapi.entity.dto.GoodsPriceDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsPriceMapper {

    @Insert("insert into goods_price " +
            "(" +
            "GoodsPriceCode, " +
            "GoodsCode, " +
            "Price, " +
            "GoodsSizeCode, " +
            "GoodsColorCode," +
            "Stock" +
            ") " +
            "VALUES (" +
            "#{goodsPrice.GoodsPriceCode} ," +
            "#{goodsPrice.GoodsCode} ," +
            "#{goodsPrice.Price} ," +
            "#{goodsPrice.GoodsSizeCode} ," +
            "#{goodsPrice.GoodsColorCode}, " +
            "#{goodsPrice.Stock} " +
            ")")
    int insert(@Param("goodsPrice") GoodsPrice goodsPrice);


    @Update("update goods_price set " +
            "GoodsCode=#{goodsPrice.GoodsCode} ," +
            "Price=#{goodsPrice.Price} ," +
            "GoodsSizeCode=#{goodsPrice.GoodsSizeCode} ," +
            "GoodsColorCode=#{goodsPrice.GoodsColorCode}, " +
            "Stock=#{goodsPrice.Stock} " +
            "where GoodsPriceCode=#{goodsPrice.GoodsPriceCode}  ")
    int update(@Param("goodsPrice") GoodsPrice goodsPrice);

    @Select("select * from goods_price where GoodsPriceCode=#{goodsPriceCode} limit 1 ")
    GoodsPrice getByGoodsPriceCode(@Param("goodsPriceCode") String goodsPriceCode);


    @Select("select * from goods_price where GoodsCode=#{goodsCode} ")
    List<GoodsPriceDTO> getByGoodsCode(@Param("goodsCode") String goodsCode);

    @Delete("delete from goods_price where GoodsPriceCode=#{goodsPriceCode} ")
    int delete(@Param("goodsPriceCode") String goodsPriceCode);


    @Select("select * from goods_price where GoodsCode=#{goodsCode} order by Price asc limit 1 ")
    GoodsPrice getFloorPrice(@Param("goodsCode") String goodsCode);


    @Select("select * from goods_price where GoodsCode=#{goodsCode} order by Price asc limit 0,1 ")
    GoodsPrice getPrice(@Param("goodsCode") String goodsCode);
}
